package com.student.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.student.dao.Dao;

public class StudentDelete extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(StudentDelete.class);
	private Dao dao;
       
    public StudentDelete() {
        super();
        dao = new Dao();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/*
	 * 删除用户
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		logger.info("User is deleting an information.");
		
		PrintWriter pw = response.getWriter();
		String id = request.getParameter("id");
		if ( id == null || id.equals("") ) {
			pw.println("<script>alert('出错了！即将返回主页！');window.location.href='StudentList';</script>");
			pw.flush();
			pw.close();
		} else {
			dao.deleteStudent(Integer.parseInt(id));
			request.getRequestDispatcher("StudentList").forward(request, response);
		}
	}

}
